//
//  DiscoverLeanCloudTableViewCell.m
//  Wifi
//
//  Created by srulos on 2017/6/15.
//  Copyright © 2017年 srulos. All rights reserved.
//

#import "DiscoverLeanCloudTableViewCell.h"
#import "WifiHeader.h"


@implementation DiscoverLeanCloudTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setup:(AVObject *)avObject
{
    _m_label_title.text = [avObject objectForKey:@"title"];
    NSString * cover = [avObject objectForKey:@"cover"];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        UIImage * image = [UIImage imageWithData:[self getDataFromCache:cover]];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            _m_imageView_cover.image = image;
        });
    });
}

- (NSData*)getDataFromCache:(NSString*)url{
    NSData * data = [[WQMemoryCacheManager stander]getData:url];
    if (data == nil) {
        data = [[WQCacheManager standard]getFile:url];
        if (data == nil) {
            data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
            [[WQCacheManager standard]writeFile:data fileName:url];
        }
        
        if (data != nil) {
            [[WQMemoryCacheManager stander]addData:data key:url];
        }
    }
    return data;
}

@end
